﻿using DatabaseCore.Sqlite;
using NW_WEB_Service.com.app.Interface;
using NW_WEB_Service.com.app.services;
using Service.src.com.utils.modal;
using Service.src.Flow.Server;
using Service.src.NW.Model.Drive;
using System.Collections.Generic;
using System.Web.Http;

namespace NW_WEB_Service.com.app.controllers
{

    [RoutePrefix("device/plc")]
    public class SysPlcController: ApiController
    {
        private PlcInterface PlcService;
        public static SysDriverAdressService AddressServer;
        public SysPlcController() {
            PlcService = new PlcService();
            AddressServer = new SysDriverAdressService();
        }

        /// <summary>
        /// 获取PLC地址
        /// </summary>
        /// <param name="DriverType"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("address/{DriverType}")]
        public HttpResult QueryByDriverType(string DriverType)
        {
            List<SysPlcDriverAddress> Address = PlcService.QueryByDriverType(DriverType);
            if (Address == null || Address.Count <= 0)
            {
                Address = new List<SysPlcDriverAddress> ();
            }
            return new HttpResult().Success(Address);
        }

        /// <summary>
        /// 根据 ID 获取Address详情数据
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        [Route("address/id/{Id:int}")]
        public HttpResult Get(int Id)
        {
            SysPlcDriverAddress info = AddressServer.GetAddressInfoById(SqliteHelper.SystemDefaultDBID, Id);
            return new HttpResult().Success(info);
        }

    
    }
}
